package com.swak.frame.exception.core;

import com.swak.frame.enums.IResultCode;
import com.swak.frame.util.GetterUtil;

/**
 * Base Exception is the parent of all exceptions
 * 
 * @author colley.ma
 * @since 2022/07/14
 */
public abstract class BaseException extends RuntimeException{

    private static final long serialVersionUID = 1L;
    
    private Integer  code;

    private String msg;

    protected BaseException(Throwable cause) {
        super(cause);
        this.msg = cause.getMessage();
    }

    public BaseException(Integer code, String msg) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public BaseException(String msg){
        super(msg);
        this.msg = msg;
    }
    
    public BaseException(String msg, Throwable e) {
        super(msg, e);
        this.msg = msg;
    }
    
    public Integer getErrCode() {
        return code;
    }

    public  String getErrMessage() {
        return this.msg;
    }

    public void setErrCode(IResultCode errCode) {
        this.code = errCode.getCode();
        this.msg = GetterUtil.getString(this.msg,errCode.getMsg());
    }

}
